{$CLEO .qa}
{$USE CLEO+}
{$USE newOpcodes}
{$USE ini}

0000: NOP 

script_name "RnPeds"

// By ArtemQa146

// 20@ ped - 10@ render
// 21@ ped - 11@ render
// 22@ ped - 12@ render
// 23@ ped - 13@ render
// 24@ ped - 14@ render
// 25@ ped - 15@ render
// 26@ ped 

const
    Peds_Find = 19@
end

0085: 16@ = 0@ // (int)
0085: 17@ = 1@ // (int)
0085: 18@ = 2@ // (int)

while true
wait 0
    if
        Player.Defined($PLAYER_CHAR)
    then
    gosub @Ped_20
    gosub @Ped_26
    gosub @Realese_animation
        if
            not $ACTIVE_INTERIOR == 0
        then
            gosub @References_remove
            continue
        end

            if or
                856D: not actor 20@ defined
                856D: not actor 21@ defined
                856D: not actor 22@ defined
                856D: not actor 23@ defined
                856D: not actor 24@ defined
                856D: not actor 25@ defined
                856D: not actor 26@ defined
            then
                Peds_Find = 0
                while 0EA7: get_any_char_no_save_recursive Peds_Find progress_to Peds_Find char_to 0@
                    if
                        02CB:   actor 0@ bounding_sphere_visible
                    then
                        4@ = 85.0
                    else
                        4@ = 25.0
                    end
                    if
                        856D: not actor 26@ defined
                    then
                        //     
                        if 02CB:   actor 0@ bounding_sphere_visible
                        then 4@ = 5.0
                        else continue
                        end
                    end
                    080E: get_actor 0@ ped_event_to 2@
                    if and
                        not 2@ == 9 // ped damaged
                        80DF: not actor 0@ driving
                        not is_char_script_controlled 0@
                        not locate_char_distance_to_char 0@ char $PLAYER_ACTOR radius 4@
                        locate_char_distance_to_char 0@ char $PLAYER_ACTOR radius 100.0
                    then
                        0A96: 2@ = actor 0@ struct
                        2@ += 0xE
                        0A8D: 4@ = read_memory 2@ size 1 virtual_protect 0
                        
                        if
                            Actor.Animation(0@) == "UMBRELLA_PARTIAL"
                        then
                            if
                                4@ == 0
                            then
                                0A8C: write_memory 2@ size 1 value 1 virtual_protect 0
                                continue
                            end
                        end

                        0EFF: get_char_simplest_active_task 0@ id_to 2@ pointer_to 3@
                        0470: 3@ = actor 0@ current_weapon
                        if and
                            4@ == 0
                            2@ == 900
                            3@ == 0 //unarmed
                            not Actor.Animation(0@) == "sprint_panic"
                            not Actor.Animation(0@) == "woman_runpanic"
                            not Actor.Animation(0@) == "idle_chat"
                        then
                            if and
                                82F2:   not actor 0@ model == 77 // homeless
                                82F2:   not actor 0@ model == 78  // homeless
                                82F2:   not actor 0@ model == 79 // homeless
                                82F2:   not actor 0@ model == 134 // homeless
                                82F2:   not actor 0@ model == 135 // homeless
                                82F2:   not actor 0@ model == 137 // homeless
                                82F2:   not actor 0@ model == 212 // homeless
                            then
                                if and
                                    82F2:   not actor 0@ model == 230 // homeless
                                    82F2:   not actor 0@ model == 239 // homeless
                                then
                                    089F: get_actor 0@ pedtype_to 1@
                                    if or
                                        1@ == 4 //man
                                        1@ == 5 //woman
                                    then
                                        04C4: store_coords_to 1@ 2@ 3@ from_actor 0@ with_offset 1.0 0.0 1.5
                                        04C4: store_coords_to 4@ 5@ 6@ from_actor 0@ with_offset -1.0 0.0 50.0
                                        if
                                            06BD:   no_obstacles_between 1@ 2@ 3@ and 4@ 5@ 6@ solid 1 car 0 actor 0 object 1 particle 0
                                        then
                                            gosub @Load_animation
                                            if
                                                056D: actor 0@ defined
                                            then
                                                if
                                                    not is_char_script_controlled 0@
                                                then

                                                    if and
                                                        not Actor.Animation(0@) == "UMBRELLA_PARTIAL"
                                                        856D: not actor 26@ defined
                                                    then
                                                        0085: 26@ = 0@ // (int)
                                                        0E0B: mark_char_as_needed 26@
                                                        gosub @Peds_animation
                                                        wait 500
                                                        break
                                                    end

                                                for 1@ = 0 to 5 step 1
                                                    if
                                                        856D: not actor 20@(1@,1i) defined
                                                    then
                                                        if
                                                            not Actor.Animation(0@) == "UMBRELLA_PARTIAL"
                                                        then
                                                            0085: 20@(1@,1i) = 0@ // (int)
                                                            0E0B: mark_char_as_needed 20@(1@,1i)
                                                            gosub @Umbrella
                                                            if or
                                                                1@ == 0
                                                                1@ == 2
                                                                1@ == 4
                                                            then
                                                                gosub @Ped_Render_Create_Left
                                                            else
                                                                gosub @Ped_Render_Create_Right
                                                            end
                                                            wait 500
                                                            break
                                                        end
                                                    end
                                                end
                                            end
                                        end
                                    end
                                end
                            end
                        end
                    end
                end
            end
        end
    end
end


//      
:Ped_Render_Create_Left
0F02:  20@(1@,1i) special_model 2@ bone 34 offset 0.01 0.035 0 rotation 0 180.0 180.0 scale 10@(1@,1i) // bone 34 left hand, 24 right hand, 9 had, 3 tors
0E30: set_render_object_auto_hide 10@(1@,1i) dead 1 weapon 1 car 1
0A1A: actor 20@(1@,1i) perform_walk_animation "RainLeft" IFP "PedEventsMod" framedelta 1000.0 loopA 0 lockX 0 lockY 0 lockF 1 -1 ms // versionC
return

//      
:Ped_Render_Create_Right
0F02:  20@(1@,1i) special_model 2@ bone 24 offset 0 0 0 rotation 0 0 0 scale 10@(1@,1i) // bone 34 left hand, 24 right hand, 9 had, 3 tors
0E30: set_render_object_auto_hide 10@(1@,1i) dead 1 weapon 1 car 1
0A1A: actor 20@(1@,1i) perform_walk_animation "RainRight" IFP "PedEventsMod" framedelta 1000.0 loopA 0 lockX 0 lockY 0 lockF 1 -1 ms // versionC
return



//    
:Ped_20
for 1@ = 0 to 5 step 1
if
    056D: actor 20@(1@,1i) defined
then
    0A96: 3@ = ped 20@(1@,1i) struct
    0D4E: 2@ = read_struct 3@ offset 0x470 size 1
    if 08B7:   test 2@ bit 3 //      
    then
        08C3: clear 2@ bit 3
        0E28: write_struct 3@ offset 0x470 size 1 value 2@ //      
        10@(1@,1i) = -1
        gosub @PedsMod_Delete_Render
        continue
    end
    if and
        not actor.Dead(20@(1@,1i))
        is_char_script_controlled 20@(1@,1i)
        locate_char_distance_to_char 20@(1@,1i) char $PLAYER_ACTOR radius 120.0
    then
        0D59: get_current_weather_to 2@
        if and
            not 2@ == 8 // weather rain
            not 2@ == 16 // weather rain 2
        then
            gosub @PedsMod_Delete_Render
            continue
        end

        if
            Actor.Animation(20@(1@,1i)) == "UMBRELLA_PARTIAL"
        then
            0A96: 2@ = actor 20@(1@,1i) struct
            2@ += 0xE
            0A8D: 3@ = read_memory 2@ size 1 virtual_protect 0
            if
                3@ == 0
            then
                0A8C: write_memory 2@ size 1 value 1 virtual_protect 0
            end
        end
        if or
            0E47: is_char_fighting 20@(1@,1i)
            Actor.Animation(20@(1@,1i)) == "UMBRELLA_PARTIAL"
            82D8:   not actor 20@(1@,1i) current_weapon == 0
            actor.Driving(20@(1@,1i))
        then
            gosub @PedsMod_Delete_Render
            continue
        end

        if
            Actor.Animation(20@(1@,1i)) == "idle_chat"
        then
            if
                not 10@(1@,1i) == -1
            then
                0E31: set_render_object_visible 10@(1@,1i) 0
            end
        else
            if
                not 10@(1@,1i) == -1
            then
                0E31: set_render_object_visible 10@(1@,1i) 1
            end
        end
        0EFF: get_char_simplest_active_task 20@(1@,1i) id_to 3@ pointer_to 2@
        if
            3@ == 900
        then
            gosub @Repeat_animation
        end
    else
        gosub @PedsMod_Delete_Render
        continue
    end
end
end
return



//      
:PedsMod_Delete_Render
if
    056D: actor 20@(1@,1i) defined
then
    if
        not locate_char_distance_to_char 20@(1@,1i) char $PLAYER_ACTOR radius 60.0
    then
        if
            0E0A: is_char_script_controlled 20@(1@,1i)
        then
            if
                not 10@(1@,1i) <= -1
            then
                0E31: set_render_object_visible 10@(1@,1i) 0
            end
            01C2: remove_references_to_actor 20@(1@,1i) // Like turning an actor into a random pedestrian
        end
    else
        if
            0E0A: is_char_script_controlled 20@(1@,1i)
        then
            if
                not 10@(1@,1i) <= -1
            then
                0E31: set_render_object_visible 10@(1@,1i) 0
            end
            if
                not actor.Dead(20@(1@,1i))
            then
                0E97: clear_char_secondary_tasks 20@(1@,1i)
            end
            01C2: remove_references_to_actor 20@(1@,1i) // Like turning an actor into a random pedestrian
            wait 500
        end
    end
end
20@(1@,1i) = -1
10@(1@,1i) = -1
return


//   
:Peds_animation
0209: 2@ = random_int_in_ranges 1 5
if 2@ == 1
then 0605: actor 26@ perform_animation "Rain1" IFP "PedEventsMod" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
end
if 2@ == 2
then 0605: actor 26@ perform_animation "Rain2" IFP "PedEventsMod" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
end
if 2@ == 3
then 0605: actor 26@ perform_animation "Rain3" IFP "PedEventsMod" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
end
if 2@ == 4
then 0605: actor 26@ perform_animation "Homeless" IFP "PedEventsMod" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
end
0006: TIMERA = 0 
return



//    ,  
:Ped_26
if
    056D: actor 26@ defined
then
    080E: get_actor 26@ ped_event_to 1@
    0D59: get_current_weather_to 2@
    if or
        1@ == 49 // shoot close ped
        actor.Dead(26@)
        not is_char_script_controlled 26@
        0019:   TIMERA > 20000
        not locate_char_distance_to_char 26@ char $PLAYER_ACTOR radius 100.0
        82D8:   not actor 26@ current_weapon == 0
        actor.Driving(26@)
    then
        01C2: remove_references_to_actor 26@ // Like turning an actor into a random pedestrian
        26@ = -1
    end
end
return



//      ,   
:Realese_animation
if and
    856D: not actor 20@ defined
    856D: not actor 21@ defined
    856D: not actor 22@ defined
    856D: not actor 23@ defined
    856D: not actor 24@ defined
    856D: not actor 25@ defined
    856D: not actor 26@ defined
then
    if
        04EE: animation "PedEventsMod" loaded
    then
        04EF: release_animation "PedEventsMod"
    end
    0D59: get_current_weather_to 1@
    if and
        not 1@ == 8 // not weather rain
        not 1@ == 16 // not weather rain 2
    then
        0A93: terminate_this_custom_script
    end
    if
        not $ACTIVE_INTERIOR == 0
    then
        0A93: terminate_this_custom_script
    end
end 
return



//   
:Umbrella
0209: 2@ = random_int_in_ranges 1 4
if 2@ == 1
then 0085: 2@ = 16@ // (int)
end
if 2@ == 2
then 0085: 2@ = 17@ // (int)
end
if 2@ == 3
then 0085: 2@ = 18@ // (int)
end
return



//     
:References_remove
for 1@ = 0 to 6 step 1
    if
        056D:   actor 20@(1@,1i) defined
    then
        01C2: remove_references_to_actor 20@(1@,1i) // Like turning an actor into a random pedestrian
        20@(1@,1i) = -1
        10@(1@,1i) = -1
    end
end
return



//  
:Load_animation
if
    84EE: not animation "PedEventsMod" loaded
then
    repeat
    wait 0
    04ED: load_animation  "PedEventsMod"
    until 04EE:   animation "PedEventsMod" loaded
end
return



//   ,    
:Repeat_animation
if or
    1@ == 0 // 20@
    1@ == 2 // 22@
    1@ == 4 // 24@
then
    if
        not Actor.Animation(20@(1@,1i)) == "RainLeft"
    then
        if and
            02CB:   actor 20@(1@,1i) bounding_sphere_visible
            timerb > 5000
        then
            0A1A: actor 20@(1@,1i) perform_walk_animation "RainLeft" IFP "PedEventsMod" framedelta 4.0 loopA 1 lockX 0 lockY 0 lockF 0 -1 ms // versionC
            timerb = 0
        end
    end
else
    if
        not Actor.Animation(20@(1@,1i)) == "RainRight"
    then
        if and
            02CB:   actor 20@(1@,1i) bounding_sphere_visible
            timerb > 5000
        then
            0A1A: actor 20@(1@,1i) perform_walk_animation "RainRight" IFP "PedEventsMod" framedelta 4.0 loopA 1 lockX 0 lockY 0 lockF 0 -1 ms // versionC
            timerb = 0
        end
    end
end
return
